package com.siashan.unipay4j.core.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 数字工具类
 *
 * @author siashan
 * @since v1.0.1
 **/
public class NumberUtil {


    public static BigDecimal div(float v1, float v2) {
        return div(new BigDecimal(Float.toString(v1)), new BigDecimal(Float.toString(v2)));
    }

    public static BigDecimal div(BigDecimal v1, BigDecimal v2) {
        return div(v1, v2, 10, RoundingMode.HALF_UP);
    }

    public static BigDecimal div(BigDecimal v1, BigDecimal v2, int scale, RoundingMode roundingMode) {

        if (null == v1) {
            return BigDecimal.ZERO;
        } else {
            if (scale < 0) {
                scale = -scale;
            }

            return v1.divide(v2, scale, roundingMode);
        }
    }
}
